package test.demos.ireport.utils;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import net.sf.jasperreports.engine.JRDataSource;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JRField;

public class ReportCustomDataSource extends CustomDataSource implements JRDataSource {

	private static final Logger log = LoggerFactory.getLogger(ReportCustomDataSource.class);

	public ReportCustomDataSource(List<Object> dataList) {
		super(dataList);
	}

	@SuppressWarnings({ "rawtypes", "unchecked" })
	@Override
	public Object getFieldValue(JRField field) throws JRException {
		try {
			String fieldName = field.getName();
			String firstCharater = fieldName.substring(0, 1);
			String firstCharaterToUpper = firstCharater.toUpperCase();
			fieldName = fieldName.replaceFirst(firstCharater, firstCharaterToUpper);
			Object object = (Object) dataList.get(index);
			Object addResult = null;
//			if (object instanceof MaterialDataBO) {
//				MaterialDataBO to = (MaterialDataBO) object;
//				Class classType = to.getClass();
//				Method getMethod = classType.getMethod("get" + fieldName);
//				addResult = getMethod.invoke(to);
//			} 
			return addResult;
		}  catch (Exception e) {
			log.error("" + e.getMessage());
			return null;
		}
	}

}
